package top.iflyoung.cim.common.enums;

import jdk.nashorn.internal.objects.annotations.Getter;

import java.util.EnumSet;

/**
 * @author liguiyang
 * @description
 * @sine 1.8
 * @date 2021/9/49:19
 **/
public enum MessageType {
    text(1), image(2), video(3), voice(4);
    private int code;

    MessageType(int code) {
        this.code = code;
    }

    public int getCode() {
        return code;
    }

    public static MessageType getTypeByCode(int code) throws NullPointerException {
        EnumSet<MessageType> types = EnumSet.allOf(MessageType.class);
        for (MessageType t : types) {
            if (t.getCode() == code) {
                return t;
            }
        }
        throw new NullPointerException("没有获取到对应的消息类型");
    }
}
